<template>
  <div class="app-container">
  <!--站点数据-->
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
      <el-form-item label="选择校区" prop="schoolId">
       <el-select v-model="queryParams.schoolId" placeholder="请选择" clearable filterable size="small" @keyup.enter.native="handleQuery" >
         <el-option
           v-for="dict in schoolOptions"
           :key="dict.value"
           :label="dict.name"
           :value="dict.id"
         />
       </el-select>
      </el-form-item>
      <el-form-item label="申请时间" prop="time">
        <el-date-picker
          v-model="queryParams.time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="状态" clearable size="small" >
          <el-option :key="999" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in runnerStatusOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="评分" prop="scoreEnd">
        <el-input
          v-model="queryParams.scoreEnd"
          placeholder="请输入"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="跑腿员类型" prop="flg">
        <el-select v-model="queryParams.flg" placeholder="类型" clearable size="small" >
          <el-option :key="999" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in runnerTypeOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="跑腿员姓名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="跑腿员手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="接单数" prop="totalOrderCountStart">
        <el-input
          v-model="queryParams.totalOrderCountStart"
          placeholder="请输入"
          clearable
          size="small"
          style="width: 120px"
          @keyup.enter.native="handleQuery"
        />
        -
        <el-input
          v-model="queryParams.totalOrderCountEnd"
          placeholder="请输入"
          clearable
          size="small"
          style="width: 120px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:user:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:user:remove']"
        >删除</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:user:export']"
        >导出</el-button>
      </el-col>-->
    </el-row>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          :type="tableTab === 1 ? 'primary':''"
          size="mini"
          @click="changType(1)"
        >全部</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :type="tableTab === 2 ? 'primary':''"
          size="mini"
          @click="changType(2)"
        >待审核</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="mobile" width="110px" />
      <el-table-column label="姓名" align="center" prop="username" />
      <el-table-column label="类型" align="center" prop="typeName" />
      <el-table-column label="等级" align="center" prop="levelId" />
      <el-table-column label="所属校区" align="center" prop="schoolName" />
      <el-table-column label="历史接单" align="center" prop="totalOrderCount" />
      <el-table-column label="申请时间" align="center" prop="createTime" />
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.stateName }}</span>
          <div v-if="scope.row.state == -1" style="color: red;">{{scope.row.unLockTime}}s</div>
        </template>
      </el-table-column>
      <el-table-column label="工作状态" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.workStateName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="钱包余额" align="center" prop="current" />
      <el-table-column label="评分" align="center" prop="score" />
      <el-table-column label="操作" align="center" width="240">
        <template slot-scope="scope">
          <template>
            <el-button
              class="tableButton"
              type="primary"
              size="mini"
              @click="handleUpdate(scope.row, '详情')"
            >查看详情</el-button>
          </template>
          <template v-if="scope.row.state !== -3 && scope.row.typeName === '平台'">
              <el-button
                class="tableButton"
                type="primary"
                size="mini"
                @click="handleUpdate(scope.row, '编辑')"
              >编辑</el-button>
              <el-button
                class="tableButton"
                type="danger"
                size="mini"
                @click="handleCancel(scope.row, '注销')"
              >注销</el-button>
          </template>
          <template v-else-if="scope.row.state !== -3 && scope.row.typeName !== '平台'">
            <el-button
              class="tableButton"
              v-if="scope.row.status !== -1"
              size="mini"
              type="success"
              @click="handleThaw(scope.row)"
            >解冻</el-button>
            <el-button
              class="tableButton"
              v-if="scope.row.status !== -2"
              size="mini"
              type="danger"
              @click="handleBlack(scope.row)"
            >拉黑</el-button>
            <el-button
              class="tableButton"
              v-else-if="scope.row.status === -2"
              size="mini"
              type="danger"
              @click="handleBlack(scope.row)"
            >取消拉黑</el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="16">
            <el-form-item label="选择校区" prop="schoolId">
              <el-select v-model="form.schoolId" placeholder="请选择" clearable filterable size="small" @change="selectSchool" >
                <el-option
                  v-for="dict in schoolOptions"
                  :key="dict.value"
                  :label="dict.name"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="跑腿员姓名" prop="username">
              <el-input v-model="form.username" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="跑腿员昵称" prop="nickName">
              <el-input v-model="form.nickName" placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="联系电话" prop="mobile">
              <el-input v-model="form.mobile" placeholder="请输入手机号码" type="text" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="上传证件照" prop="idCardFront">
              <el-col :span="12">
                <el-upload
                  class="avatar-uploader sfz"
                  :class="this.form.idCardFront?'disUoloadSty':''"
                  :action="uploadImgUrl"
                  :headers="headers"
                  :data="{'type': 'IMG_USER_CARD'}"
                  :on-preview="handlePreview"
                  :before-upload="beforeUpload"
                  :on-success="handleSuccess"
                  :on-remove="handleRemove"
                  :file-list="fileList"
                  list-type="picture-card"
                  accept='.jpg,.jpeg,.png,.gif'
                  :limit="1"
                >
                  <img v-if="!this.form.idCardFront" style="width: 98%;" src="../../../assets/image/idcardzm.png" />
                </el-upload>
              </el-col>
              <el-col :span="12">
                <el-upload
                  class="avatar-uploader sfz"
                  :class="this.form.idCardBack?'disUoloadSty':''"
                  :action="uploadImgUrl"
                  :headers="headers"
                  :data="{'type': 'IMG_USER_CARD'}"
                  :on-preview="handlePreview"
                  :before-upload="beforeUpload1"
                  :on-success="handleSuccess1"
                  :on-remove="handleRemove1"
                  :file-list="fileList1"
                  list-type="picture-card"
                  accept='.jpg,.jpeg,.png,.gif'
                  :limit="1"
                >
                  <img v-if="!this.form.idCardBack" style="width: 98%;" src="../../../assets/image/idcardfm.png" />
                </el-upload>
              </el-col>

            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" placeholder="请选择">
                <el-option
                  v-for="dict in sexOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="是否启用" prop="state">
              <el-switch
                v-model="form.state"
                :active-value="1"
                :inactive-value="0"
              />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="紧急联系人1" prop="tel1">
              <el-input v-model="form.tel1" placeholder="请输入手机号码" maxlength="11" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="紧急联系人2" prop="tel2">
              <el-input v-model="form.tel2" placeholder="请输入手机号码" maxlength="11" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="有效期" prop="time">
              <el-date-picker
                v-model="form.time"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详细 -->
    <el-dialog title="详细" :visible.sync="detailOpen" width="800px">
      <el-form ref="form" :model="form" label-width="120px" size="mini">
        <div v-if="form.typeName === '平台'" style="margin: 0 0 20px 0;">
          <el-button
            type="primary"
            size="mini"
            @click="handleUpdate(form, '编辑')"
          >编辑</el-button>
        </div>
        <el-row style="margin-bottom: 20px;">
          <el-col :span="8"><div>类型: {{ form.typeName }}跑腿员</div></el-col>
          <el-col :span="8"><div>状态: {{ form.stateName }}</div></el-col>
          <el-col :span="8"><div>当前工作状态: {{ form.workStateName }}</div></el-col>
        </el-row>
        <el-row style="margin-bottom: 20px;">
          <el-col :span="8"><div>跑腿等级: {{ form.typeName }}</div></el-col>
          <el-col :span="8"><div>历史接单数: {{ form.totalOrderCountStart }}</div></el-col>
          <el-col :span="4"><div>评分: {{ form.workStateName }}</div></el-col>
          <el-col :span="4"><div style="color: #46A6FF;cursor: pointer;">提现记录</div></el-col>
        </el-row>

        <el-row>
          <el-col :span="3">
            <div style="width: 100px;height: 100px;border-radius: 50%;overflow: hidden;">
              <img style="height: 100%;" v-if="form.head" :src="form.head" >
              <img style="height: 100%;" v-else-if src="../../../assets/image/defaultHead.png" >
            </div>
          </el-col>
          <el-col :span="10">
            <el-col :span="20">
              <el-form-item label="跑腿员姓名：">{{ form.username }}</el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="跑腿员昵称：">{{ form.nickName }}</el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="手机号：">{{ form.mobile }}</el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="绑定微信号：">{{ form.wechat }}</el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="年龄：">{{ form.age }}</el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="性别：">
                <div v-if="form.sex === '0'">男</div>
                <div v-else-if="form.sex === '1'">女</div>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="所属校区：">{{ form.schoolName }}</el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="紧急联系人1：">{{ form.tel1 }}</el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="紧急联系人2：">{{ form.tel2 }}</el-form-item>
            </el-col>
            <el-col>
              <el-form-item v-if="form.typeName !== '平台'" label="申请时间：">{{ form.createTime }}</el-form-item>
              <el-form-item v-else label="创建时间：">{{ form.createTime }}</el-form-item>
            </el-col>
            <el-col>
              <el-form-item v-if="form.typeName !== '平台'" label="审批人：">{{ form.checkOperator }}</el-form-item>
              <el-form-item v-else label="创建人：">{{ form.insertOperator }}</el-form-item>
            </el-col>
          </el-col>
          <el-col :span="11">
            <el-col>
              <el-form-item label="身份证正面：">
                <el-col :span="12">
                  <img style="width: 200px;" :src="form.idCardFront" alt="身份证正面" />
                </el-col>
              </el-form-item>
              <el-form-item label="身份证背面：">
                <el-col :span="12">
                  <img style="width: 200px;" :src="form.idCardBack"  alt="身份证背面" />
                </el-col>
              </el-form-item>
              <el-form-item v-if="form.typeName !== '平台' && form.stuCard" label="学生证：">
                <el-col :span="12">
                  <img style="width: 200px;" :src="form.stuCard"  alt="学生证：" />
                </el-col>
              </el-form-item>
              </el-col>
          </el-col>
        </el-row>
        <div style="display: flex;align-items: center;justify-content: center;" v-if="form.checkFlg == 1">
          <el-button @click="handleCheck(0)">不通过</el-button>
          <el-button type="primary" @click="handleCheck(1)">通过审核</el-button>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="changeAreaModal = true" type="primary">更改区域</el-button>
        <el-button @click="detailOpen = false">关 闭</el-button>
      </div>

      <el-dialog
        width="30%"
        title="更改区域"
        :visible.sync="changeAreaModal"
        append-to-body>
        <el-col :span="12">
          <el-form>
            <el-form-item label="选择区域">
              <el-col :span="12">
                <el-select
                 v-model="form.schoolId"
                 @change="triggerToChangeArea"
                 filterable
                  placeholder="选择区域"
                  size="small"
                  style="width: 240px"
                  >
                  <el-option
                    v-for="item in areaList"
                    :key="item.key"
                    :label="item.value"
                    :value="item.key">
                  </el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-form>
        </el-col>
         <div slot="footer" class="dialog-footer">
          <el-button @click="changeAreaModal = false">关 闭</el-button>
        </div>
      </el-dialog>
    </el-dialog>

  </div>
</template>

<script>
import { exportUser } from "@/api/system/user";
import {
  listRunner,
  listRunnerCheck,
  listRunnerDetails,
  listRunnerCheckDetails,
  runnerOption,
  addRunner,
  editRunner,
  blackRunner,
  unBlackRunner,
  cancelRunner,
  thawRunner,
  uploadImg,
  checkRunner,
  getRunnerAreaList,
  changeRunnerArea
} from "@/api/pt/runner.js";
import { listSchool } from "@/api/pt/school.js";
import { getToken } from "@/utils/auth";

export default {
  name: "Runner",
  components: {},
  data() {
    let validateIdCardBack = (rule, value, callback) => {
      if (value) {
        if (!this.form.idCardBack) {
          callback(new Error("请上传身份证背面照"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    return {
      changeAreaModal: false,
      areaList: [],
      fileList: [
        // {name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'},
      ],
      fileList1: [
        // {name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'},
      ],
      uploadImgUrl: process.env.VUE_APP_BASE_API + "/applet/oss/upload", // 上传的图片服务器地址
      // uploadImgUrl: "https://jsonplaceholder.typicode.com/posts/", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      // tabletab切换
      tableTab: 1,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户表格数据
      tableList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      selectId: "",
      // 日期范围
      dateRange: [],
      // 性别状态字典
      sexOptions: [],
      // 已有校区所在城市数据
      ownCity: [],
      // 已有校区数据
      schoolOptions: [],
      // 跑腿员状态
      runnerStatusOptions: [],
      // 跑腿员类型
      runnerTypeOptions: [],
      // 表单参数
      form: {},
      //详情打开
      detailOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolId: undefined,
        time: undefined,
        state: undefined,
        scoreEnd: undefined,
        flg: undefined,
        username: undefined,
        mobile: undefined,
        totalOrderCountStart: undefined,
        totalOrderCountEnd: undefined,
      },
      options: {
        img: "", //裁剪图片的地址
        autoCrop: true, // 是否默认生成截图框
        autoCropWidth: 200, // 默认生成截图框宽度
        autoCropHeight: 200, // 默认生成截图框高度
        fixedBox: true, // 固定截图框大小 不允许改变
      },
      // 表单校验
      rules: {
        username: [
          { required: true, message: "站点名称不能为空", trigger: "blur" },
        ],
        schoolId: [{ required: true, message: "请选择校区", trigger: "blur" }],
        mobile: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        tel1: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        tel2: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        time: [{ required: true, message: "请选择时间", trigger: "blur" }],
        idCardFront: [
          { required: true, message: "请上传身份证正面照", trigger: "blur" },
          { required: true, trigger: "blur", validator: validateIdCardBack },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_user_sex").then((response) => {
      this.sexOptions = response.data;
    });
    listSchool({ pageNum: 1, pageSize: 10000 }).then((response) => {
      let list = response.data.list;
      let lArr = "";
      let listArr = [];
      list.map((item) => {
        if (lArr.indexOf(item.city) == -1) {
          lArr += "," + item.city;
        }
      });
      lArr = lArr.split(",");
      lArr.map((item) => {
        listArr.push({
          label: item ? item : "全部",
          value: item,
        });
      });
      this.schoolOptions = response.data.list;
      this.ownCity = listArr;
    });
    runnerOption().then((response) => {
      this.runnerStatusOptions = response.data.state;
      this.runnerTypeOptions = response.data.type;
    });
  },
  methods: {
    triggerToChangeArea(e) {
      const _this = this;
      changeRunnerArea({ id: this.form.id, schoolId: Number(e) }).then(res => {
        _this.msgSuccess('修改成功')
      })
    },
    handleCheck(state) {
      let pa = {
        id: this.selectId,
        msg: "",
        result: state,
      };
      if (state === 1) {
        this.$confirm(`是否通过审核？`, "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return checkRunner(pa.id, pa);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("修改成功");
            this.detailOpen = false;
          })
          .catch(function () {});
      } else {
        this.$prompt("请输入不通过理由", "不通过", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        })
          .then(({ value }) => {
            pa.msg = value;
            return checkRunner(pa.id, pa);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("修改成功");
            this.detailOpen = false;
          })
          .catch(() => {});
      }
    },
    // tab切换
    changType(e) {
      this.tableTab = e;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      if (this.tableTab === 2) {
        listRunnerCheck(
          this.addDateRange2(
            this.queryParams,
            "createTimeStart",
            "createTimeEnd"
          )
        ).then((response) => {
          this.tableList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        });
      } else {
        listRunner(
          this.addDateRange2(
            this.queryParams,
            "createTimeStart",
            "createTimeEnd"
          )
        ).then((response) => {
          this.tableList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        });
      }

      getRunnerAreaList().then(res => {
        this.areaList = res.data.school
      })
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === 0 ? "启用" : "关闭";
      this.$confirm("确认要" + text + '"' + row.name + '"吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          row.time = [new Date(row.startTime), new Date(row.endTime)];
          return addSchool(row);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.fileList = [];
      this.fileList1 = [];
      this.resetForm("form");
      this.$nextTick(() => {
        this.form = {
          id: undefined,
          schoolId: undefined,
          username: undefined,
          nickName: undefined,
          mobile: undefined,
          idCardFront: undefined,
          idCardBack: undefined,
          sex: undefined,
          state: undefined,
          tel1: undefined,
          tel2: undefined,
        };
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
      this.queryParams.totalOrderCountEnd = undefined;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      console.log(row);
      this.selectId = row.id;
      this.title = "修改";
      // row.time = [new Date(row.startTime),new Date(row.endTime)]
      // this.form = row
      this.fileList = [];
      this.fileList1 = [];
      if (this.tableList === 2) {
        listRunnerCheckDetails(row.id).then((response) => {
          this.form = response.data;
          this.form.time = [
            new Date(response.data.startTime),
            new Date(response.data.endTime),
          ];
          this.form.sex = JSON.stringify(this.form.sex);
          this.form.schoolId = JSON.stringify(this.form.schoolId);
          if (type != "详情" && this.form.idCardFront) {
            this.fileList.push({
              name: "123",
              url: this.form.idCardFront,
            });
          }
          if (type != "详情" && this.form.idCardBack) {
            this.fileList1.push({
              name: "123",
              url: this.form.idCardBack,
            });
          }
        });
      } else {
        listRunnerDetails(row.id).then((response) => {
          this.form = response.data;
          this.form.time = [
            new Date(response.data.startTime),
            new Date(response.data.endTime),
          ];
          this.form.sex = JSON.stringify(this.form.sex);
          this.form.schoolId = this.form.schoolId ? JSON.stringify(this.form.schoolId) : undefined;
          if (type != "详情" && this.form.idCardFront) {
            this.fileList.push({
              name: "123",
              url: this.form.idCardFront,
            });
          }
          if (type != "详情" && this.form.idCardBack) {
            this.fileList1.push({
              name: "123",
              url: this.form.idCardBack,
            });
          }
        });
      }
      if (type === "详情") {
        this.detailOpen = true;
      } else {
        this.open = true;
      }
    },

    /** 提交按钮 */
    submitForm: function () {
      // this.form.idCardBack = 123
      // this.form.idCardFront = 123
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.time) {
            this.form.startTime = this.parseTime(this.form.time[0]);
            this.form.endTime = this.parseTime(
              this.form.time[1],
              "{y}-{m}-{d} {23}:{59}:{59}"
            );
          }
          delete this.form.time;
          if (this.form.id !== undefined) {
            editRunner(this.form.id, this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
          } else {
            this.form.id = undefined;
            addRunner(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.message);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleBlack(row) {
      const Ids = row.id || this.ids;
      let text = "";
      let pa = {};
      if (row.status === 2) {
        this.$confirm(`是否取消拉黑"${row.username}"客户？`, "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return unBlackRunner(row.id);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("修改成功");
          })
          .catch(function () {});
      } else {
        pa.id = row.id || this.ids;
        this.$prompt("请输入拉黑理由", "拉黑理由", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        })
          .then(({ value }) => {
            let pa = {
              msg: value,
            };
            return blackRunner(row.id, pa);
          })
          .catch(() => {});
      }
    },
    /* 注销*/
    handleCancel(row, type) {
      this.$confirm(`注销后不可恢复，请谨慎操作`, "警告", {
        confirmButtonText: "确定注销",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return cancelRunner(row.id);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("注销成功");
        })
        .catch(function () {});
    },
    /** 修改按钮操作 */
    handleThaw(row, type) {
      this.$confirm(`是否确认解冻"${row.username}"跑腿员？`, "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return thawRunner(row.id);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("修改成功");
        })
        .catch(function () {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有用户数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportUser(queryParams);
        })
        .then((response) => {
          this.fileDownload(response.data, "用户管理.xlsx");
        })
        .catch(function () {});
    },

    // 获取当前选中校区所在城市
    selectSchool(val) {
      this.schoolOptions.map((item) => {
        if (item.id === val) this.form.city = item.city;
      });
    },
    handlePreview(file) {
      console.log(file);
    },
    beforeUpload(file, fileList) {
      console.log("beforeUpload");
      // this.uploadImg1(file).then(res=>{
      //   this.form.idCardFront = res.data
      // })
    },
    beforeUpload1(file, fileList) {
      console.log("beforeUpload");
      // this.uploadImg1(file).then(res=>{
      //   this.form.idCardBack = res.data
      // })
    },
    handleRemove(file, fileList) {
      console.log("handleRemove");
      this.fileList.splice(0, 1);
      this.form.idCardFront = "";
    },
    handleRemove1(file, fileList) {
      console.log("handleRemove");
      this.fileList1 = [];
      this.form.idCardBack = "";
    },
    handleSuccess(file, fileList) {
      console.log("handleSuccess");
      console.log(file);
      console.log(fileList);
      this.form.idCardFront = file.data;
    },
    handleSuccess1(file, fileList) {
      console.log("handleSuccess");
      console.log(file);
      console.log(fileList);
      this.form.idCardBack = file.data;
    },
    // 上传图片
    uploadImg1(file) {
      let formData = new FormData();
      formData.append("file", file);
      formData.append("type", "IMG_USER_CARD");
      return uploadImg(formData);
    },
  },
};
</script>

<style type="text/css">
.dian {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: #999;
  margin-right: 6px;
}
</style>
